#include "StdAfx.h"
#include "Event.h"

using namespace BAA;

int Event::event_counter = 0;

Event::Event(Agent * source, std::vector<Agent*> * targets, 
			std::vector<Agent*> * agentsInvolved,
			int urgency, int priority, BAA::Action * action)
{
	FILETIME ft;
    SYSTEMTIME st;

    GetSystemTime(&st);				// Gets the current system time
    SystemTimeToFileTime(&st, &ft);	// Converts the current system time to file time format
	memcpy(&timeStamp, &ft, sizeof(__int64) );
	timeStamp = timeStamp / 10000;	// Keep it in milliseconds

	//TODO: fill out GameTime object

	this->source = source;							//may be null; if null, source = unknown
	this->agentsInvolved = agentsInvolved;
	this->urgency = urgency;
	this->priority = priority;
	this->targets = targets;
	this->action = action;
	this->event_id = Event::event_counter;
	Event::event_counter++;

	//calculate location of event
	//this->location = location;
}

Event::~Event(void)
{
	//TODO: clean up action
	delete action;
	//TODO: clean up vectors BUT NOT THEIR CONTENTS
	delete targets;
	delete agentsInvolved;
}

/*
	getDescription will build a human readable description of the event.
*/
std::string Event::getDescription(){
	std::ostringstream ss;

	//TODO: fill this in with real agent data.
	//TODO: complete the event data output
	ss << "Event: " << event_id << ". Action: " << action->Name() << "." << std::endl;

	return ss.str();
}

#pragma region Accessors
__int64 Event::getTimestamp(){
	return this->timeStamp;
}
std::vector<Agent *> * Event::getAgentsInvolved(){
	return agentsInvolved;
}
std::vector<Agent *> * Event::getTargets(){
	return targets;
}
int Event::getUrgency(){
	return urgency;
}
int Event::getPriority(){
	return priority;
}
int Event::getEventID(){
	return event_id;
}
Agent * Event::getSource(){
	return source;
}
BAA::Action * Event::getAction(){
	return action;
}

void Event::addInvolvedAgent(Agent * a){
	agentsInvolved->push_back(a);
}
void Event::addTarget(Agent * a){
	targets->push_back(a);
}
void Event::setUrgency(int urg){
	urgency = urg;
}
void Event::setPriority(int pri){
	priority = pri;
}
void Event::setAction(BAA::Action * type){
	action = type;
}
#pragma endregion

void Event::testClass(){
	//what is there to test, accessors?
	std::cout << this->getDescription();
}